package com.wicket.okrframework.web.contorller;

import com.github.pagehelper.Page;
import com.wicket.okrframework.biz.service.CommonService;
import com.wicket.okrframework.biz.service.dto.req.*;
import com.wicket.okrframework.biz.service.dto.res.*;
import com.wicket.okrframework.common.ro.OkrResult;
import com.wicket.okrframework.common.util.CommonFunctionHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：
 * @date ：
 *
 *
 * @version 1.0
 */
@RestController
@RequestMapping("/base/common/")
public class CommonController {

    @Autowired
    CommonService commonService;

    /**
   * 空间信息存储缓存
   */
    @PostMapping("putSpaceInfoToRedis")
    public OkrResult<PutSpaceInfoToRedisRespDto> putSpaceInfoToRedis(@RequestBody @Validated PutSpaceInfoToRedisReqDto reqDTO){
    return OkrResult.success(commonService.putSpaceInfoToRedis(reqDTO));
    }

    /**
   * D1查询空间框架信息前端缓存
   */
    @PostMapping("queryFrontPublicInfoList")
    public OkrResult<QueryFrontPublicInfoListRespDto> queryFrontPublicInfoList(@RequestBody @Validated QueryFrontPublicInfoListReqDto reqDTO){
    Page<?> page = CommonFunctionHelper.startPage(reqDTO.getPageNum(),reqDTO.getPageSize());

        QueryFrontPublicInfoListRespDto retData = commonService.queryFrontPublicInfoList(reqDTO);

        retData.setPageNum(page.getPageNum());
        retData.setPageSize(page.getPageSize());
        retData.setTotalNum(page.getTotal());
        return OkrResult.success(retData);
    
    }

    /**
   * D1-发布单条数据
   */
    @PostMapping("releaseSingleData")
    public OkrResult<ReleaseSingleDataRespDto> releaseSingleData(@RequestBody @Validated ReleaseSingleDataReqDto reqDTO){
    return OkrResult.success(commonService.releaseSingleData(reqDTO));
    }

    /**
   * D1-撤销存档批次下单条数据
   */
    @PostMapping("undoArchiveBatchSingleData")
    public OkrResult<UndoArchiveBatchSingleDataRespDto> undoArchiveBatchSingleData(@RequestBody @Validated UndoArchiveBatchSingleDataReqDto reqDTO){
    return OkrResult.success(commonService.undoArchiveBatchSingleData(reqDTO));
    }

    /**
   * D1-存档批次下单条数据
   */
    @PostMapping("archiveBatchSingleData")
    public OkrResult<ArchiveBatchSingleDataRespDto> archiveBatchSingleData(@RequestBody @Validated ArchiveBatchSingleDataReqDto reqDTO){
    return OkrResult.success(commonService.archiveBatchSingleData(reqDTO));
    }

    /**
   * D1-修改排序
   */
    @PostMapping("updateSortNum")
    public OkrResult<UpdateSortNumRespDto> updateSortNum(@RequestBody @Validated UpdateSortNumReqDto reqDTO){
    return OkrResult.success(commonService.updateSortNum(reqDTO));
    }

    /**
   * D1-删除单条数据
   */
    @PostMapping("deleteSingleData")
    public OkrResult<DeleteSingleDataRespDto> deleteSingleData(@RequestBody @Validated DeleteSingleDataReqDto reqDTO){
    return OkrResult.success(commonService.deleteSingleData(reqDTO));
    }

    /**
   * D1-存档单条数据
   */
    @PostMapping("archiveSingleData")
    public OkrResult<ArchiveSingleDataRespDto> archiveSingleData(@RequestBody @Validated ArchiveSingleDataReqDto reqDTO){
    return OkrResult.success(commonService.archiveSingleData(reqDTO));
    }

    /**
   * D-批量改排序
   */
    @PostMapping("batchUpdateSortNum")
    public OkrResult<BatchUpdateSortNumRespDto> batchUpdateSortNum(@RequestBody @Validated BatchUpdateSortNumReqDto reqDTO){
    return OkrResult.success(commonService.batchUpdateSortNum(reqDTO));
    }

    /**
   * D上传附件
   */
    @PostMapping("addUploadFile")
    public OkrResult<AddUploadFileRespDto> addUploadFile(@RequestBody @Validated AddUploadFileReqDto reqDTO){
    return OkrResult.success(commonService.addUploadFile(reqDTO));
    }
}
